package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.SysCompanyControllerApi;
import com.nineclock.system.dto.*;
import com.nineclock.system.service.SysCompanyService;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RequestMapping("/company")
@RestController
public class SysCompanyController implements SysCompanyControllerApi {
    @Autowired
    private SysCompanyService sysCompanyService;
    @Autowired
    private SysCompanyUserService sysCompanyUserService;
    //加入企业
    @Override
    @PostMapping("/allowedJoinCompany")
    public Result allowedJoinCompany(SysAllowedJoinCompanyUserDTO sysAllowedJoinCompanyUserDTO){
        sysCompanyService.allowedJoinCompany(sysAllowedJoinCompanyUserDTO);
        return Result.success();
    }
    @Override
    @PostMapping("/applyJoinCompany")
    public Result applyJoinCompany(@RequestBody SysApplyJoinCompanyUserDTO sysApplyJoinCompanyUserDTO) {
        sysCompanyService.applyJoinCompany(sysApplyJoinCompanyUserDTO);
        return Result.success();
    }
    @Override
    @GetMapping("/list")
    public Result<List<SysCompanyDTO>> queryCompanyByName(String keyword) {
        List<SysCompanyDTO> companyDTOList = sysCompanyService.queryCompanyByName(keyword);
        return Result.success(companyDTOList);
    }

    //查看管理员信息
    @Override
    @GetMapping("/getCurrentAdmin")
    public Result<SysCompanyUserDTO> queryCompanyManagerInfo() {
        SysCompanyUserDTO sysCompanyUserDTO= sysCompanyUserService.queryCompanyManagerInfo();
        return Result.success(sysCompanyUserDTO);
    }

    //查询当前企业信息
    @Override
    @GetMapping
    public Result<SysCompanyDTO> queryCompanyInfo() {

        return sysCompanyService.queryCompanyInfo();
    }

    //上传logo
    @Override
    @PostMapping("/uploadOSS")
    public Result<String> updateCompanyLogo(MultipartFile file) throws IOException {
        String d4c = sysCompanyService.updateCompanyLogo(file);
        return Result.success(d4c);
    }

    //更新信息
    @Override
    @PutMapping
    public Result updateCompanyInfo(@RequestBody SysCompanyDTO sysCompanyDTO) {
        sysCompanyService.updateCompanyInfo(sysCompanyDTO);
        return Result.success();
    }

    @Override
    @PostMapping("/config/admin")
    public Result exchangeManager(@RequestBody SysChangeMainManagerDTO sysChangeMainManagerDTO) {
        sysCompanyUserService.exchangeManager(sysChangeMainManagerDTO);
        return Result.success();
    }

    @Override

    public Result<List<SysCompanyDTO>> findCompanyBySome(String some) {
        return null;
    }
}
